package cn.hncj.lyc.listener;

import java.util.Map;

import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

import com.aliyuncs.exceptions.ClientException;

import cn.hncj.lyc.utils.SmsUtil;

@Component
@RabbitListener(queues = "sms")
@PropertySource(value="classpath:zhongwen.properties",encoding = "UTF-8")
public class SmsListener {   
    @Autowired
    private SmsUtil smsUtil;
    @Value("${aliyun.sms.template_code}")
    private String template_code;
    @Value("${aliyun.sms.sign_name}")
    private String sign_name;

    @RabbitHandler
    public void executeSms(Map<String,String> map){
        String mobile = map.get("mobile");
        String checkcode = map.get("checkcode");
        try {
            smsUtil.sendSms(mobile,template_code,sign_name,"{\"code\":\""+checkcode+"\"}");
            System.out.println(template_code);
            System.out.println(sign_name);
        } catch (ClientException e) {                    
            e.printStackTrace();
        }
    }
}